package com.escool.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.escool.model.TbGrado;
import com.escool.model.TbNivel;

import com.escool.model.TbTipoCobro;
import com.escool.service.CatTipoCobroService;

import com.escool.service.GradosService;
import com.escool.service.NivelesService;
import com.escool.service.RolService;

@Controller
public class CatTipoCobroController {
	
	@Autowired
	CatTipoCobroService catTipoCobroService;

	
	@RequestMapping("showCatTipoCobro")
	public String showCatTipoCobro(Map<String, Object> map){
		map.put("CatTipoCobro", new TbTipoCobro());
		map.put("TbTipoCobroList", catTipoCobroService.listTbTipoCobro());
		return "/catTipoCobro";
	}
	
	@RequestMapping(value = "addCatTipoCobro", method = RequestMethod.POST)
	public String addRoles(@ModelAttribute("CatTipoCobro") @Valid TbTipoCobro tbCatTipoCobro, BindingResult result){
		if (!result.hasErrors()) {
			catTipoCobroService.addTbTipoCobro(tbCatTipoCobro);
			return "redirect:/showCatTipoCobro";
		}
		return "";
	}
	
	@RequestMapping(value = "editCatTipoCobro", method = RequestMethod.POST)
	public String editRoles(@ModelAttribute("CatTipoCobro") @Valid TbTipoCobro tbCatTipoCobro, BindingResult result){
		if (!result.hasErrors()) {
			catTipoCobroService.editTbTipoCobro(tbCatTipoCobro);
			return "redirect:/showCatTipoCobro";
		}
		return "";
	}
	
	@RequestMapping(value = "deleteCatTipoCobro", method = RequestMethod.POST)
	public String delRoles(@ModelAttribute("CatTipoCobro") @Valid TbTipoCobro tbCatTipoCobro, BindingResult result){
		if (!result.hasErrors()) {
			catTipoCobroService.delTbTipoCobro(tbCatTipoCobro.getIdTipoCobro());
			return "redirect:/showCatTipoCobro";
		}
		return "";
	}

}
